package edu.ccut.saturn.component.impl.directory;

import org.osgi.framework.Bundle;

import edu.ccut.saturn.component.IBundleInfo;
import edu.ccut.saturn.component.IFileResourceInfo;
import edu.ccut.saturn.component.ILogger;
import edu.ccut.saturn.component.SaturnLoggerManager;

/**
 * 文件资源的抽象类，实现了接口<code>IFileResourceInfo</code>，定义了描述文件资源的基本信息：
 * <li>字段fileName：记录了文件资源的文件名称
 * <li>字段directoryPath：记录了文件资源在bundle中的相对路径信息
 * 
 * @author 温建
 * @version 1.0 2008.8.27
 * 
 * @see IFileResourceInfo
 * 
 */
public abstract class AbstractFileResourceInfo implements IFileResourceInfo {

	private static final String LOGGER_KEY_LOAD_BUNDLE = SaturnLoggerManager.LOGGER_KEY_LOAD_BUNDLE;

	protected static ILogger logger = SaturnLoggerManager.getInstance()
			.getSaturnLogger(LOGGER_KEY_LOAD_BUNDLE);

	private String fileName = null;

	private String directoryPath = null;

	public AbstractFileResourceInfo(String fileName) {
		this.fileName = fileName;
	}

	public String getDirectoryPath() {
		return this.directoryPath;
	}

	public String getFileName() {
		return this.fileName;
	}

	public void setDirectoryPath(String directoryPath) {
		this.directoryPath = directoryPath;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public abstract void load(Bundle bundle, IBundleInfo bundleInfo);

	public void unload(Bundle bundle, IBundleInfo bundleInfo) {
	}

	public String getFilePath() {

		if (this.directoryPath != null || "".equals(this.directoryPath)) {
			return this.directoryPath + "/" + this.fileName;
		}
		return this.fileName;
	}
}
